package com.example.tkserver.service.impl;

import com.example.tkserver.dao.RedisCacheDao;
import com.example.tkserver.service.interfaces.MainService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Log4j2
public class MainServiceImpl implements MainService {

    @Autowired
    RedisCacheDao redisCacheDao;
    
    @Override
    public String getNotice() {
        String notice = redisCacheDao.get("notice");
        if (notice == null || notice.isEmpty()){
            redisCacheDao.add("notice","暂无公告...");
            notice = "暂无公告...";
        }
        return notice;
    }

    @Override
    public List<String> getSwiper() {
        List<String> result = redisCacheDao.getList("swiper",String.class);
        if (result == null || result.isEmpty()){
            redisCacheDao.add("swiper",new ArrayList<>());
            result = new ArrayList<>();
        }
        return result;
    }
}
